package cn.anc.aonicardv.widget;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.TextView;

import cn.anc.aonicardv.R;

/**
 * Created by yangdai on 2017/5/19.
 */

public class TitlePopWindow extends PopupWindow {

    private Activity c;

    public TextView titleTv;

    public TextView rightTv;

    public TextView backTv;

    public OnClickListener onClickListener;

    public TitlePopWindow(int width, int height, Activity c, ViewGroup viewGroup) {
        super(width, height);
        this.c = c;
        init(viewGroup);
    }

    private void init(ViewGroup viewGroup) {
        View v = LayoutInflater.from(c).inflate(R.layout.pop_image_show_bar, viewGroup, false);
        setContentView(v);
        setAnimationStyle(R.style.TitlePopWindowStyle);
        titleTv = (TextView) v.findViewById(R.id.tv_title);
        rightTv = (TextView) v.findViewById(R.id.tv_right);
        backTv = (TextView) v.findViewById(R.id.tv_back);
        backTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               if (onClickListener!=null)
                   onClickListener.leftOnClick();
            }
        });
        rightTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onClickListener!=null)
                    onClickListener.rightOnClick();
            }
        });
    }

    public void setTitle(String title) {
        titleTv.setText(title);
    }

    public void setTextColor(int coloRes) {
        titleTv.setTextColor(c.getResources().getColor(coloRes));
    }

    public void setRightText(String text) {
        rightTv.setText(text);
    }


    public void setOnClickListener(OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    public  interface OnClickListener{

        void rightOnClick();

        void leftOnClick();

    }

}
